<HTML>
<HEAD>
<TITLE>
Buffer.cpp
</TITLE>
</HEAD>
<BODY>
<PRE>
<font color="blue">#include</font> <font color="maroon">"Buffer.h"</font>

Buffer<font color="black">:</font><font color="black">:</font>Buffer<font color="black">(</font><font color="black">)</font> <font color="black">{</font>
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tamanio<font color="black">=</font><font color="maroon">0</font>;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>pointer<font color="black">=</font>NULL;
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>ListEspaciosLibres <font color="black">=</font> <font color="blue">new</font> vector<font color="black">&#60;</font><font color="blue">unsigned</font> <font color="blue">int</font><font color="black">&#62;</font><font color="black">(</font><font color="black">)</font>;
<font color="black">}</font> 

Buffer<font color="black">*</font> Buffer<font color="black">:</font><font color="black">:</font>instancia <font color="black">=</font> NULL;

Buffer<font color="black">:</font><font color="black">:</font>~Buffer<font color="black">(</font><font color="black">)</font> <font color="black">{</font>
    <font color="blue">delete</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>ListEspaciosLibres;
<font color="black">}</font>

vector<font color="black">&#60;</font><font color="blue">unsigned</font> <font color="blue">int</font><font color="black">&#62;</font><font color="black">*</font> Buffer<font color="black">:</font><font color="black">:</font>getListEspaciosLibres<font color="black">(</font><font color="black">)</font><font color="black">{</font>
    <font color="blue">return</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>ListEspaciosLibres;
<font color="black">}</font>

Buffer <font color="black">*</font> Buffer<font color="black">:</font><font color="black">:</font>getInstance<font color="black">(</font><font color="black">)</font> <font color="black">{</font>
    <font color="blue">if</font> <font color="black">(</font><font color="black">!</font>instancia<font color="black">)</font>
        instancia <font color="black">=</font> <font color="blue">new</font> Buffer<font color="black">(</font><font color="black">)</font>;
    <font color="blue">return</font> <font color="black">(</font>instancia<font color="black">)</font>;
<font color="black">}</font>

<font color="blue">void</font><font color="black">*</font> Buffer<font color="black">:</font><font color="black">:</font>getPointer<font color="black">(</font><font color="black">)</font><font color="black">{</font>
    <font color="blue">if</font> <font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>pointer<font color="black">=</font><font color="black">=</font>NULL<font color="black">)</font>
        <font color="blue">throw</font> <font color="blue">new</font> NullPointerException<font color="black">(</font><font color="black">)</font>;
    <font color="blue">else</font>
        <font color="blue">return</font><font color="black">(</font>pointer<font color="black">)</font>;
<font color="black">}</font>

<font color="blue">unsigned</font> <font color="blue">int</font> Buffer<font color="black">:</font><font color="black">:</font>getTamanio<font color="black">(</font><font color="black">)</font><font color="black">{</font>
    <font color="blue">return</font><font color="black">(</font>tamanio<font color="black">)</font>;
<font color="black">}</font>

<font color="blue">void</font> Buffer<font color="black">:</font><font color="black">:</font>setTamanio<font color="black">(</font><font color="blue">unsigned</font> <font color="blue">int</font> tam<font color="black">)</font><font color="black">{</font>
    <font color="blue">if</font> <font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tamanio<font color="black">=</font><font color="black">=</font><font color="maroon">0</font><font color="black">)</font><font color="black">{</font>
        <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>tamanio<font color="black">=</font>tam;
        <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>pointer<font color="black">=</font> malloc<font color="black">(</font>tam<font color="black">)</font>;
        <font color="blue">if</font> <font color="black">(</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>pointer<font color="black">=</font><font color="black">=</font> NULL<font color="black">)</font>
            <font color="blue">throw</font> <font color="blue">new</font> MemoryStorageException<font color="black">(</font>StorageException<font color="black">:</font><font color="black">:</font>escritura<font color="black">)</font>;
    <font color="black">}</font>
    <font color="blue">else</font> <font color="blue">throw</font> IllegalOperation<font color="black">(</font><font color="black">)</font>;
<font color="black">}</font>

</PRE>
</BODY>
</HTML>
